{%extends 'layout.html'%}
{%set title="User: '%s'"%user.nickname%}
{%block stylesheets%}
{{super()}}
{{css('users/user')}}
{%if current_user and user.key()==current_user.key()%}
{%endif%}
{%endblock%}
{%block javascript%}
{{super()}}
{%if current_user%} {{js('items/list')}} {%endif%}
{%if current_user and user.key()==current_user.key()%}
{{js('image-editing')}}
{{js('users/profile-editing')}}
{{js('rich-text')}}
{%endif%}
{%endblock%}
{%block content%}
{%from 'items/macros.html' import item with context%}
{%if current_user and user.key()==current_user.key()%}
<form id="thumbnail" style="background-image:url('{{user|url(action='picture')}}')" class="image-editable" method="post" action="{{current_user|url(action='set_picture')}}" data-sizes="512 72" data-field-name="picture">
	<div>Drag Image Here</div>
	{{csrf_field()}}
	<input type="submit" value="Upload" class="image-submit"/>
</form>
{%else%}
<div id="thumbnail" class="image-viewable" style="background-image:url('{{user|url(action='picture')}}')"></div>
{%endif%}
<div id="right">
	<div class="labeled">
		<span>Nickname:</span>
		{%if current_user and user.key()==current_user.key()%}
		<form id="nickname-form" method="post" action="{{user|url(action='nickname')}}">
			{{csrf_field()}}
			<input type="text" name="nickname" value="{{user.nickname}}" size="{{user.nickname|length}}"/>
		</form>
		{%else%}
		{{user.nickname}}
		{%endif%}
	</div>
	{%if current_user and user.key()==current_user.key()%}
	<a href="{{current_user|url(action='delete')}}">Delete All Your Data</a>
	{%endif%}
	{%if current_user and current_user.admin%}
	<div class="labeled">
		<span>E-Mail:</span>
		{{user.email}}
	</div>
	<form action="{{user|url(action='deactivate')}}" method="post" data-confirmation-message="Do you really want to deactivate this user?">
		{{csrf_field()}}
		{%if user.deactivated%}
		<input type="submit" value="User Already Deactivated" disabled class="admin-button"/>
		{%else%}
		<input type="submit" value="Deactivate this user" class="admin-button"/>
		{%endif%}
	</form>
	<form action="{{user|url(action='promote')}}" method="post" data-confirmation-message="Do you really want to promote this user?">
		{{csrf_field()}}
		{%if user.admin%}
		<input type="submit" value="User Already has Admin Privlages" disabled class="admin-button"/>
		{%else%}
		<input type="submit" value="Make this user an Admin" class="admin-button"/>
		{%endif%}
	</form>
	{%endif%}
	{%if current_user and user.key()==current_user.key()%}
	<form method="post" id="description" data-completing-label="Updating..." action="{{current_user|url(action='description')}}">
		{{csrf_field()}}
		<textarea name="description"></textarea>
		<div class="rich-text" data-form="description" data-field="description">
			{{user.description|Markup}}
		</div>
		<input type="submit" value="Update"/>
	</form>
	{%else%}
	<div id="description">
		{{user.description|Markup}}
	</div>
	{%endif%}
</div>
<div id="clearer"></div>
<div id="items">
	<h1>{{'Fresh ' if current_user and (current_user.admin or current_user.key()==user.key()) else ''}}Items</h1>
	{%if current_user and current_user.key()==user.key()%}<a href="/items/add" id="add-item-link">Add an Item</a>{%endif%}
	{%for itm in fresh_items %}
	{{item(itm)}}
	{%endfor%}
	{%if current_user and (current_user.admin or current_user.key()==user.key()) %}
	<h1>Expired Items</h1>
	{%for itm in expired_items%}
	{{item(itm)}}
	{%endfor%}
	{%endif%}
</div>
{%endblock%}